package com.suneee.base.sendmsg;

import com.suneee.base.sendmsg.bean.SendMsgBean;
import com.suneee.base.sendmsg.bean.SendType;
import com.suneee.base.sendmsg.mail.SendEMailMsgServiceImpl;
import com.suneee.base.sendmsg.sms.SendSmsMsgServiceImpl;
import com.suneee.base.util.ContextHelper;

public class SendSmsFactory {

	private SendEMailMsgServiceImpl	sendEMailMsgServiceImpl	= null;
	private SendSmsMsgServiceImpl sendSmsMsgServiceImpl = null;
	
	public ISendMsgService getSendServiceInstance(SendMsgBean sendBean){
		sendEMailMsgServiceImpl = ContextHelper.getBean("sendEMailMsgServiceImpl", SendEMailMsgServiceImpl.class);
		sendSmsMsgServiceImpl = ContextHelper.getBean("sendSmsMsgServiceImpl", SendSmsMsgServiceImpl.class);
		if (null == sendBean.getSendType()){
			return null;
		}
		if (compare(SendType.SEND_EMAIL, sendBean.getSendType())){
			return sendEMailMsgServiceImpl;
		}else if(compare(SendType.SEND_SMS, sendBean.getSendType())){
			return sendSmsMsgServiceImpl;
		}
		return null;
	}
	
	/**
	 * 比较两个类型是否相同
	 * @param src
	 * @param desc
	 * @return
	 */
	private boolean compare(Enum<SendType> src, Enum<SendType> desc){
		return src.ordinal() == desc.ordinal();
	}
}
